/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui;

import java.util.Vector;

/**
 *
 * @author tho.hoang
 */
public class FormItemCollections {

    private Vector collection = new Vector();

    public FormItemCollections() {
    }

    public int size() {
        return collection.size();
    }

    public AFormItem elementAt(int i) {
        return (AFormItem) collection.elementAt(i);
    }

    public void addElement(AFormItem item, ACanvas parent) {
        boolean isHas = false;
        AFormItem a = null;
        for (int i = 0; i < collection.size(); i++) {
            a = (AFormItem) collection.elementAt(i);
            if (a == item || a.getId().equals(item.getId())) {
                isHas = true;
                break;
            }
        }
        if (!isHas) {
            collection.addElement(item);
            item.setParent(parent);
            return;
        }
        throw new IllegalArgumentException("Them hoai vay!!!!");
    }

    public void removeElementAt(int index) {
        collection.removeElementAt(index);
    }

    public void removeElement(AFormItem item) {
        int index = -1;
        AFormItem a = null;
        for (int i = 0; i < collection.size(); i++) {
            a = (AFormItem) collection.elementAt(i);
            if (a == item || a.getId().equals(item.getId())) {
                index = i;
                break;
            }
        }

        if (index != -1) {
            removeElementAt(index);
        }
    }

    public void removeAllElements() {
        collection.removeAllElements();
    }
}
